package com.company.controller;

import java.util.Date;
import java.util.Random;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.company.dao.Company;
import com.company.dao.Employee;
import com.company.dao.User;
import com.company.exception.DAOException;
import com.company.exception.ServiceException;
import com.company.jms.OrderService;
import com.company.service.CompanyService;
import com.company.service.Service;

@Controller
public class UserController {

	@Autowired
	private Service service;
	
	@Autowired
	private CompanyService companyService;
	
	@Autowired
	private OrderService orderService;
	
	@RequestMapping(value = "/user/list", method = RequestMethod.GET)
	public String list(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws ServiceException, DAOException { 
		model.addAttribute("message", "Spring 33"); 				
		
//		User user = new User();
//		user.setId(1);
//		user.setUsername("edited : " + Math.random());
//		
//		Employee employee = new Employee();
//		employee.setId(1);
//		employee.setName("name : " + Math.random());
//		employee.setAge(new Random().nextLong());
//		employee.setDob(new Date());
//		employee.setStatus(false);
//		
//		service.saveUser(user, employee);
//		
//		Company company = new Company();
//		company.setId(1);
//		company.setName("company : " + Math.random());
//		
//		companyService.saveCompany(company);
		
		for(int i =1; i<=5; i++) {
            orderService.sendOrder(1+i, 10.0D+i);
    	}
		
		return "listuser";
	}
}
